home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 18
/
018.d81
/
comal tutor#5
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
27KB
|
681 lines
5 ifpeek(51200)<>76orpeek(52016)<>32then7
6 ifpeek(52080)=173andpeek(52176)=169then8
7 load"routines v4",8,1
8 pokev+33,1:q$=chr$(34)
10 r=53265:c=128:v=53248:s=v+1024:li=52016:wi=51200:cl=51203:su=51206:sd=51209
12 pokes+23,.:pokes+4,128:pokev+32,14
15 gosub1000:print" [215]elcome to the fifth chapter of"
16 print"[204]oadstar's [195][207][205][193][204][160]0.14 [212]utorial. [201]n
17 [153]"the previous chapter, we converted our
18 print"now-familiar [195]elsius program into a
19 [153]"asc(NULL)(NULL)lention, as well as learned about the
20 print"[201]mmediate [205]ode and other concepts. [201]f
21 [153]"you are unsure of any of these, you
22 print"may wish to [211][212][207][208] this lesson now and
23 [153]"take a previous lesson or three before
24 print"returning here.":gosub1200
25 print" [201]n this chapter, we will expand on
26 [153]"our knowledge of asc(NULL)(NULL)lentions, and also
27 print"introduce some other kinds of [208][210][207][199][210][193][205]-
28 [153]"(NULL)right$(NULL)chr$close(NULL)(NULL)(NULL)(NULL)len(NULL)(NULL)(NULL)val(NULL). ascirst, let's (NULL)(NULL)atnstr$
29 print"our work of last installment:
30 [153]" (NULL)(NULL)atnstr$ "q$"len.asc.lenval(NULL)(NULL)right$(NULL)(NULL)"q$"
34 gosub1160:x%=.:y%=14:gosub1110:print"9902 [194][217][212][197][211][160][198][210][197][197]."
35 gosub1300:x%=.:y%=16:a$="[204][207][193][196] "+q$+"[195].[198].[195][197][204][211][201][213][211]"+q$:gosub1600
36 ifethena$=mid$(a$,e):e=.:gosub1605:goto36
37 gosub1500:ifk$<>chr$(13)then37
38 s=5:gosub2000:gosub1035:gosub1150
39 print"[144][146][196]one! [199]uess what we're gonna do next?":gosub1205
40 print" [210]ight! [217]ou're gonna [204][201][211][212] it:
45 [141]1160:[141]1300:x%[178].:y%[178]18:a$[178]"(NULL)right$(NULL)(NULL)":[141]1600
46 [139]e[167]a$[178][202](a$,e):e[178].:[141]1605:[137]46
47 [141]1500:[139]k$[179][177][199](13)[167]47
48 [153]:[153]"0010 asc(NULL)(NULL)lencloselenval(NULL)(NULL)right$(NULL)(NULL)(ascatn(NULL)val(NULL)left$valright$(NULL))":[153]"0020 (NULL)val(NULL)(NULL)(NULL)(NULL)close(ascatn(NULL)val(NULL)left$valright$(NULL)-32)*(5/9)
49 print"0030 [197][206][196][198][213][206][195][160][195][197][204][211][201][213][211]":gosub1150
50 print"[144] [199]ood! [201]t still seems to be there:
51 [153]"the asc(NULL)(NULL)len statement in line 10 which
52 print"names the [198][213][206][195]tion and specifies the
53 [153]"argument, the (NULL)val(NULL)(NULL)(NULL)(NULL) statement in line
54 print"20 which specifies how to compute the
55 [153]"value of the asc(NULL)(NULL)lention given the argu-
56 print"ment, and the [197][206][196][198][213][206][195] in line 30 which
57 [153]"marks the end of the asc(NULL)(NULL)lention.":[141]1205
60 [153]" (NULL)ast issue, we mentioned that a
61 print"[198][213][206][195]tion must have [193][212][160][204][197][193][211][212][160][207][206][197][160][210][197][212][213][210][206]
62 [153]"statement. (NULL)hen might a asc(NULL)(NULL)lention need
63 print"more than 1? [193] [198][213][206][195]tion can't [210][197][212][213][210][206]
64 [153]"more than 1 value per call! (NULL)ell, right$
65 print"will show you an example later, but
66 [153]"first, we'll need to experiment some
67 print"more with [201]mmediate mode, and learn a
68 [153]"new concept or 3. (NULL)hen, we'll use
69 print"those concepts in a new [198][213][206][195]tion!":gosub1200
70 print" [198]rom our experiments, you know that
71 [153]"the symbols '+', '-', '*' and '/' mean
72 print"addition, subtraction, multiplication
73 [153]"and division, respectively. (NULL)uch sym-
74 print"bols used in an expression are called
75 [153]"(NULL)(NULL)val(NULL)atn(NULL)(NULL)(NULL)(NULL). (NULL)he values they operate on
76 print"are called [207][208][197][210][193][206][196][211]. [215]hat they do
77 [153]"with the operands is called an (NULL)(NULL)val(NULL)atn-
78 print"[212][201][207][206]. [195]lear as mud, right? [193]llow me
79 [153]"to use an example:":[141]1200
80 [153]" chr$iven the expression '5/9', the (NULL)(NULL)-
81 print"[197][210][193][212][207][210] is '/', the [207][208][197][210][193][206][196]s are '5' &
82 [153]"'9', and the (NULL)(NULL)val(NULL)atn(NULL)right$(NULL)(NULL)closeis division.
83 print" [200]ere is a more complex expression:
84 [153]"'(ascatn(NULL)val(NULL)left$valright$(NULL)-32)*(5/9)'. right$t has 3 op-
85 print"erations: '[198][193][210][197][206][200][197][201][212]-32', '5/9' & the
86 [153]"product of the results of those two.
87 print"[212]hus, the result of an operation can
88 [153]"be an operand of another operation!":[141]1200
90 [153]" right$n the case '(ascatn(NULL)val(NULL)left$valright$(NULL)-32)*(5/9)',
91 print"the operator is '*', the operands are
92 [153]"the results of 'ascatn(NULL)val(NULL)left$valright$(NULL)-32' &close'5/9',
93 print"and the operation is multiplication.
94 [153]"(NULL)e already did '5/9', so that leaves
95 print"'[198][193][210][197][206][200][197][201][212]-32'. [212]he operator is '-',
96 [153]"the operands are the value of the var-
97 print"iable '[198][193][210][197][206][200][197][201][212]' &[160]'32', and the op-
98 [153]"eration is subtraction. (NULL)arentheses
99 print"separate operations.":gosub1200
100 print" [193]re there any more operators be-
101 [153]"sides the four arithmetic ones? (NULL)es,
102 print"there is '^', which means 'exponenti-
103 [153]"ation', or 'raising to a power'. (NULL)ot
104 print"only that, but '+' and '-' can mean
105 [153]"other things besides addition and sub-
106 print"traction. [201]f they have only one oper-
107 [153]"and (after the operator), they mean
108 print"'identity'[160](no change) and 'negation'
109 [153]"(change sign), respectively.":[141]1200
110 [153]" '+' even has another meaning, which
111 print"we'll cover in a future installment.
112 [153]" (NULL)et's experiment with a new class
113 print"of operators. [212]ype this:
114 [153]" (NULL)(NULL)right$(NULL)(NULL)close2=2
115 gosub1160:gosub1300:x%=.:y%=23:a$="[208][210][201][206][212] 2=2":gosub1600
116 ifethena$=mid$(a$,e):e=.:gosub1605:goto116
117 gosub1500:ifk$<>chr$(13)then117
118 print:print"1";:gosub1700:gosub1700:gosub1035:gosub1150:print"[145][144]
119 [153]" (NULL)ay (NULL)left$atn(NULL)!? (NULL)et's try another. . .":[141]1205
120 [153]" (NULL)ype: (NULL)(NULL)right$(NULL)(NULL)close2=3
125 gosub1160:gosub1300:x%=.:y%=24:a$="[208][210][201][206][212] 2=3":gosub1600
126 ifethena$=mid$(a$,e):e=.:gosub1605:goto126
127 gosub1500:ifk$<>chr$(13)then127
128 gosub1700:print"0";:gosub1700:gosub1700:gosub1035:gosub1150:print"[145][144]
130 [153]"left$mmm . . . '2=2' is 1, and '2=3' is 0.
131 print"[211]eems to be a pattern here. [212]ype:
132 [153]" (NULL)(NULL)right$(NULL)(NULL)close2<3
135 gosub1160:x%=.:y%=24:a$="[208][210][201][206][212] 2<3":gosub1600
136 ifethena$=mid$(a$,e):e=.:gosub1605:goto136
137 gosub1500:ifk$<>chr$(13)then137
138 gosub1700:print"1";:gosub1700:gosub1700:gosub1035:gosub1150:print"[145][144]
140 [153]" right$nteresting! ascrom (NULL)ath class, you
141 print"may remember that '=' means 'is equal
142 [153]"to', and '<' means 'is less than'!":[141]1205
145 [153]" right$t seems that with an expression
146 print"which could only be [212][210][213][197] or [198][193][204][211][197], [195][207]-
147 [153]"(NULL)atn(NULL)closereturns '1' for (NULL)(NULL)(NULL)valcloseand '0' for
148 print"[198][193][204][211][197]. [207]perators such as '=' and '<',
149 [153]"which return the truth of relation-
150 print"ships (such as 'is equal to' or 'is
151 [153]"less than') between their operands,
152 print"are called [210][197][204][193][212][201][207][206][193][204][160][207][208][197][210][193][212][207][210][211].":gosub1200
155 print" [200]ere are some of these [210][197][204][193][212][201][207][206][193][204]
156 [153]"(NULL)(NULL)val(NULL)atn(NULL)(NULL)(NULL)(NULL):
157 print" '=' ([201]s [197]qual [212]o)
158 [153]" '<' (right$s (NULL)ess (NULL)han)
159 p